﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OcmKeep
{
    class RegWriter
    {
        
        /// <summary> 
        /// 设置程序开机启动 
        /// 或取消开机启动 
        /// </summary> 
        /// <param name="started">设置开机启动，或者取消开机启动</param> 
        /// <param name="exeName">注册表中程序的名字</param> 
        /// <param name="path">开机启动的程序路径</param> 
        /// <returns>开启或则停用是否成功</returns> 
        public static bool write(string value)
        {
            try
            {
                RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Anke\\CheckIn", true);//打开注册表子项 
                if (key == null)//如果该项不存在的话，则创建该子项 
                {
                    key = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Anke\\CheckIn");
                }
                key.SetValue(GetTimeStamp(), value);
                key.Close();
            }catch(Exception e){
                Api.util.LogHelper.WriteLog(typeof(Exception), e.Message+"/r/n"+e.StackTrace);
            }
            return true;
        }

        private static string GetTimeStamp()
        {
            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return Convert.ToInt64(ts.TotalSeconds).ToString();
        }
    }
}
